# 先安装 pymysql
# pip install pymysql==1.0.2 -i https://pypi.tuna.tsinghua.edu.cn/simple/
from pymysql import Connection
conn = Connection(
    host="localhost",       # 主机名
    port=3306,              # 端口号
    user="root",            # 用户
    password="cao20001009"  # 密码
)

# print(conn.get_server_info())
cursor = conn.cursor()      # 获取游标对象
# 选择数据库
conn.select_db("atguigudb")
# 执行sql
# cursor.execute("create table test_pymysql2(id int)")
cursor.execute("select employee_id,first_name,date_format(hire_date, '%Y-%m-%d'),salary from employees")

result = cursor.fetchall()      # 返回的是元组tuple
# print(result)
for res in result:
    print(res)


# 关闭连接
conn.close()

